#ifndef __EMB_H__
#define __EMB_H__

#include "main.h"




#define EMB_TIMEOUT 10


typedef enum
{
    TERMINAL_LOWER,
    TERMINAL_UPPER,
	
}EMB1428_NUM_t;



typedef enum
{
    CELL_1 = 1,
    CELL_2,  // = 2
    CELL_3,
    CELL_4,
    CELL_5,
    CELL_6,
    CELL_7,
    CELL_8,
    CELL_9,
    CELL_10,
    CELL_11,
    CELL_12, // = 12
	
}CELL_NUM_t;

typedef enum
{
    EMB_READY,
    EMB_ERROR,
    EMB_WARNING,
    EMB_CHARGE_BUSY,
    EMB_DISCHARGE_BUSY,
	
}EMB_STATUS_t;


typedef int (*emb_spi_transmit_receive_fpt)(EMB1428_NUM_t emb1428_num, uint8_t *p_tx_data, uint8_t tx_size, uint8_t *p_rx_data, uint8_t rx_size);

typedef struct
{
    uint8_t emb_fault_status[2];
    uint8_t emb_fault_code[2];
	CELL_NUM_t charge_cell_num;
	CELL_NUM_t discharge_cell_num;
    EMB_STATUS_t emb_status;
    
    emb_spi_transmit_receive_fpt emb_spi_transmit_receive;
}EMB_t;

void emb_initialization(EMB_t *emb);
int emb_charge_controller(EMB_t *emb, CELL_NUM_t cell_num);
int emb_discharge_controller(EMB_t *emb, CELL_NUM_t cell_num);

int emb_selftest_single(EMB_t *emb, EMB1428_NUM_t emb1428_num);
int emb_open_all_switches(EMB_t *emb);

int emb_vset_pwm_start(void);
int emb_selftest(EMB_t *emb);


void emb_reset(EMB_t *emb);

#endif /* __EMB_H__ */